package com.ibiz.bx.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibiz.bx.domain.BXD;
import com.ibiz.bx.service.BXDService;
import com.ibiz.bx.service.dto.BXDSearchFilter;
import com.ibiz.ibizutil.errors.BadRequestAlertException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigInteger;
import java.util.List;

@RestController
@RequestMapping("/bx/bxd")
public class BXDResource
{
	@Autowired
	private BXDService service;


	@PostMapping(value = "/getDraft")
	public ResponseEntity<BXD> getDraft(@Validated @RequestBody BXD data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("报销单[getDraft]操作发生错误","BXD","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<BXD> update(@Validated @RequestBody BXD data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("报销单[update]操作发生错误","BXD",data.getBxdid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<BXD> checkKey(@Validated @RequestBody BXD data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("报销单[checkKey]操作发生错误","BXD",data.getBxdid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<BXD> remove(@Validated @RequestBody BXD data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("报销单[remove]操作发生错误","BXD",data.getBxdid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<BXD> get(@Validated @PathVariable String id){
		BXD data=new BXD();
		data.setBxdid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("报销单[get]操作发生错误","BXD",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<BXD> create(@Validated @RequestBody BXD data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("报销单[create]操作发生错误","BXD",data.getBxdid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<BXD>> searchDefaultPage(@Validated @RequestBody BXDSearchFilter filter){
		Page<BXD> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listdefault")
	public ResponseEntity<List<BXD>> listDefault(@Validated @RequestBody BXDSearchFilter filter){
		List<BXD> searchResult = service.listDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}
}
